package com.curator.modbus;

import io.netty.channel.nio.NioEventLoopGroup;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;

/**
 * modbus 客户端构造器
 *
 * @author Jun
 * @since 2024/4/14
 */
@Getter
public class ModbusClientCreator {

    /**
     * 客户端 IO 线程池
     */
    @Setter
    public static NioEventLoopGroup workerGroup =new NioEventLoopGroup();

    /**
     * ip 默认为 127.0.0.1
     */
    private String ip = "127.0.0.1";

    /**
     * 端口，默认：8234
     */
    private int port = 8234;

    /**
     * 自动重连
     */
    private boolean reconnect = true;

    /**
     * 重连的间隔时间，单位毫秒，默认：5000
     */
    private long reInterval = 5000;

    /**
     * 连续重连次数，当连续重连这么多次都失败时，不再重连。0和负数则一直重连
     */
    private int retryCount = 0;

    public ModbusClientCreator ip(String ip) {
        this.ip = ip;
        return this;
    }

    public ModbusClientCreator port(int port) {
        this.port = port;
        return this;
    }

    public ModbusClientCreator reconnect(boolean reconnect) {
        this.reconnect = reconnect;
        return this;
    }

    public ModbusClientCreator reInterval(long reInterval) {
        this.reInterval = reInterval;
        return this;
    }


    public ModbusClientCreator retryCount(int retryCount) {
        this.retryCount = retryCount;
        return this;
    }
}
